import { NgModule } from '@angular/core';
import { Routes, RouterModule, Resolve } from '@angular/router';
import {HomeComponent} from './home/home.component';
import {ProductComponent} from './product/product.component';
import {Code404Component} from './code404/code404.component';
import {ProductDescComponent} from './product-desc/product-desc.component';
import {SellerInfoComponent} from './seller-info/seller-info.component';
import { ChatComponent } from "./chat/chat.component";
import { LoginGuard } from "./guard/login.guard";
import { UnsavedGuard } from "./guard/unsaved.guard";
import { ProductResolve } from "./guard/product.resolve";

const routes: Routes = [
  {
    path: '', redirectTo: '/home', pathMatch: 'full'
  },
  {
    path: 'chat',
    component: ChatComponent,
    outlet: 'aux',
    children: []
  },
  {
    path: 'home',
    component: HomeComponent,
    children: []
  },
  {
    path: 'product/:id',
    component: ProductComponent,
    children: [
      {path: '', component: ProductDescComponent},
      {path: 'seller/:id', component: SellerInfoComponent}
    ],
    // canActivate: [LoginGuard],     //进入路由守卫
    // canDeactivate: [UnsavedGuard]   //离开路由守卫
    resolve: {
      product: ProductResolve
    }
  },
  {
    path: '**',
    component: Code404Component,
    children: []
  }
];
//路由是由上往下找的。统配的写在最后面。上面都找不到时，才匹配下面的。

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [LoginGuard,UnsavedGuard,ProductResolve]
})
export class AppRoutingModule { }
